<template lang="pug">
  .pendant-icon.ovv-icon.hand.tac(v-if='hasOvvIcon', @click="goBackOvv") {{getBackText}}
</template>

<script>
// import { isIos } from '@/utils'
import { destroyAllAudio } from '@/utils/audio'
// let onceBtn = false
export default {
  data() {
    return {
      curUrl: ''
    }
  },

  computed: {
    hasOvvIcon() {
      return this.$route.query && (this.$route.query.ovv != null || this.$route.query.tour != null)
    },
    getBackUrl() {
      if (this.$route.query.ovv) {
        this.curUrl = '/overview/' + this.$route.query.ovv
      } else if (this.$route.query.tour) {
        this.curUrl = '/tourview/' + this.$route.query.tour
      }
      return this.curUrl
    },
    getBackText() {
      if (this.$route.query.tour) {
        return '返回地图'
      }
      return '返回总览'
    }
  },
  methods: {
    goBackOvv() {
      this.$store.dispatch('clearLoadInfo')
      destroyAllAudio()
      this.$router.replace(this.getBackUrl)
      // 测试安卓分享后无法返回
      setTimeout(() => {
        this.$router.go(0)
      }, 100)
      // if(this.getBackUrl !== window.location.href) {
      //   setTimeout(function() {
      //     window.location.reload()
      //   }, 100)
      // }
    }
  },
}
</script>

<style lang="stylus" scoped>
@import '../../assets/styles/color.styl'
.ovv-icon
  position: fixed
  top: 21px
  left: 50%
  padding: 5px 9px
  border-radius: 25px
  font-size: 12px
  color: $white
  background-color: $danger
  transform: translateX(-50%)
  z-index: 9999
  i
    color: $success
</style>
